package net.ib.mtalk.ui.attachment.vcard.account;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;

public class AccountData {
	
    private String mName;
    private String mType;
    private CharSequence mTypeLabel;
    private boolean readOnly;
    private Drawable mIcon;

    /**
     * @param name The name of the account. This is usually the user's email address or
     *        username.
     * @param description The description for this account. This will be dictated by the
     *        type of account returned, and can be obtained from the system AccountManager.
     */
    public AccountData(Context context, String name, String type, String packageName, int labelId, int iconId) {
        mName = name;
        mType = type;

        // The type string is stored in a resource, so we need to convert it into something
        // human readable.
        PackageManager pm = context.getPackageManager();

        if (labelId != 0) {
            mTypeLabel = pm.getText(packageName, labelId, null);
            if (mTypeLabel == null) {
                throw new IllegalArgumentException("LabelID provided, but label not found");
            }
        } else {
            mTypeLabel = "";
        }

        if (iconId != 0) {
            mIcon = pm.getDrawable(packageName, iconId, null);
            if (mIcon == null) {
                throw new IllegalArgumentException("IconID provided, but drawable not " +
                        "found");
            }
        } else {
            mIcon = context.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
        }
        
    }

    public String getName() {
        return mName;
    }

    public String getType() {
        return mType;
    }

    public CharSequence getTypeLabel() {
        return mTypeLabel;
    }

    public Drawable getIcon() {
        return mIcon;
    }

    public String toString() {
        return mName;
    }
}
